<template>
    <div class="comBox">
        <div>
            <span>
                <router-link to="/login" class="login">登录</router-link> 
            </span>
            <span> / </span>
            <span class="register-text">注册</span>
        </div>
        <p>
           请选择你要加入的企业 
        </p>
        <!-- <el-input :style="{ 'width': 327 + 'px' }" v-model="comName" placeholder="请输入公司全称"></el-input> -->
        <el-select v-model="existGroup" filterable placeholder="请输入公司全称" style="width: 327px " clearable>
            <el-option
            v-for="item in groupList"
            :key="item.id"
            :label="item.aliasName"
            :value="item.aliasName">
            </el-option>
        </el-select>
        <p class="created">
           或创建一个新的企业 
        </p>
        <el-input :style="{ 'width': 327 + 'px' }" v-model="newGroup" placeholder="请输入公司全称"></el-input>
        <div class="btnGroup">
            <el-button style="background: #4065E0; color: #fff; width: 108px; margin-right: 80px" @click="defineCreat">确认</el-button>
            <el-button type="text" :style="{ 'color': '#999' }" @click="cancelCreat">稍后再说</el-button>
        </div>
    </div>
</template>

<script>
import { getGroupList, joinGroup } from 'api/UserController/UserController'
import { mapGetters, mapMutations } from 'vuex'
export default {
    data() {
        return {
            existGroup: '',
            newGroup: '',
            groupList: []
        }
    },
    watch: {
        
    },
    methods: {
        ...mapMutations([
            'saveGroupInfo'
        ]),
        defineCreat(){
            var params = {
                existGroupName: this.existGroup,
                newGroupName: this.newGroup
            }
            var nngUserId = this.nngUserId
            joinGroup(params,nngUserId).then(res => {
                console.log(res)
                // res.data = { groupId: '',groupName: '',nngUid: '' }
                if(res.resultCode == 1){
                    // 存 groupInfo
                    this.saveGroupInfo(res.data)
                    // window.localStorage.setItem('groupInfo', JSON.stringify(res.data))

                    this.$message.success(res.resultMsg)
                    this.$router.push({ name: 'Login' })
                }else{
                    this.$message.warning(res.resultMsg)
                }
            })
            
        },
        cancelCreat(){
            this.$router.push({ name: 'Login' })
        }
    },
    computed: {
        ...mapGetters([
            'nngUserId'
        ])
    },
    created(){
        getGroupList().then(res => {
            this.groupList = res.data
        })
        // console.log(this.nngUserId)
    }
}
</script>

<style lang="scss" scoped>
.comBox{
    margin-top: 56px;
    .login{
        color: #bbbbbb;
        font-size: 16px;
    }
    .register-text{
        color: #666666;
        font-size: 16px;
    }
    p{
        margin-top: 56px;
        margin-bottom: 10px;
        font-size: 14px;
    }
    .created{
        margin-top: 28px;
    }
    .btnGroup{
        margin-top: 60px;
    }
}
</style>

